package cn.dslcode.security.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class UserController {

    @GetMapping("/")
    private ModelAndView index() {
        return new ModelAndView("index");
    }

    @RequestMapping(value = "/authentication/require", method = RequestMethod.GET)
    public ModelAndView loginPage() {
        return new ModelAndView("login");
    }


    @GetMapping("user/list/page")
    @PreAuthorize("hasAuthority('USER_VIEW')")
    public ModelAndView userListPage() {
        return new ModelAndView("userList");
    }

    @GetMapping("user/edit/page")
    @PreAuthorize("hasAuthority('USER_EDIT')")
    public ModelAndView userEditPage() {
        return new ModelAndView("userEdit");
    }

    @GetMapping("error/{page}")
    public ModelAndView errorPage(@PathVariable(name = "page") String page) {
        return new ModelAndView(page);
    }

}